package sma.sync.model;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class DestFolder extends Folder {

	SourceFolder sourceFolder;

	public void setSourceFolder(SourceFolder pSourceFolder) {
		sourceFolder = pSourceFolder;
	}

	public DestFolder(File pSource) {
		super(pSource);
	}
	
	Map<File, File> sourceToDestDir = new HashMap<File, File>();

	/**
	 * Get the calculated Map
	 * 
	 * @return
	 */
	public Map<File, File> getSourceToDestDir() {
		return sourceToDestDir;
	}

	@Override
	public void analyse() {
		this.recurseInDir(baseFolder);
		sLog.debug("sourceToDestDir.size()=" + sourceToDestDir.size() + " for " + baseFolder);
		sLog.debug("sourceToDestDir=" + sourceToDestDir);
		sLog.info("ignoredExtensions=" + ignoredExtensions);
	}

	@Override
	protected void addFile(File pDestFolder, File pDestFile) {
		File sourceDir = sourceFolder.filesTofolders.get(pDestFile.getName());
		if (sourceDir != null) {
			// previous control
			File alreadyDest = sourceToDestDir.get(sourceDir);
			if (alreadyDest != null) {
				if (!alreadyDest.equals(pDestFolder)) {
					sLog.warn("There was already an association for " + pDestFile + " : " + sourceDir + " to " + alreadyDest);
				}
			}
			sourceToDestDir.put(sourceDir, pDestFolder);
		} else {
			sLog.debug("No source directory found for [" + pDestFile + "] !");
		}
	}

}
